package com.example.baserecyclerviewadapterdemo.activity.node;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.adapter.node.section.NodeSectionAdapter;
import com.example.baserecyclerviewadapterdemo.base.BaseActivity;
import com.example.baserecyclerviewadapterdemo.entity.node.section.ItemNode;
import com.example.baserecyclerviewadapterdemo.entity.node.section.RootNode;

import java.util.ArrayList;
import java.util.List;

public class NodeSectionActivity extends BaseActivity {
    private RecyclerView recyclerView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_node_section);

        getParentToolbar().setTitle("Node Use(Section)");
        getParentToolbar().setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        recyclerView = findViewById(R.id.rv_list);
        recyclerView.setLayoutManager(new GridLayoutManager(this,3));

        View view = getLayoutInflater().inflate(R.layout.layout_head_view,recyclerView,false);
        view.findViewById(R.id.iv).setVisibility(View.GONE);
        NodeSectionAdapter adapter = new NodeSectionAdapter();
        adapter.addHeaderView(view);
        recyclerView.setAdapter(adapter);
        adapter.setList(getNodes());
        recyclerView.scheduleLayoutAnimation();
    }

    private List<BaseNode> getNodes(){
        List<BaseNode> baseNodes = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            List<BaseNode> itemNodes = new ArrayList<>();
            for (int j = 0; j < 5; j++) {
                ItemNode itemNode = new ItemNode(R.mipmap.animation_img1,"Root " + i + "-" + j);
                itemNodes.add(itemNode);
            }
            RootNode rootNode = new RootNode(itemNodes,"RootNode " + i);
            if (i == 1) {
                rootNode.setExpanded(false);
            }
            baseNodes.add(rootNode);
        }
        return baseNodes;
    }
}
